package com.example.linyiquan.app.util;

import android.content.Context;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.example.linyiquan.app.beam.AppBeam;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by linyiquan on 17-4-15.
 */

public class Utils {

    public static List<AppBeam> getApps(Context context) {
        List<AppBeam> list = new ArrayList<>();//创建list对象
        PackageManager pm = context.getPackageManager();//获取app的管理
        List<PackageInfo> packs = pm.getInstalledPackages(0);//获取自主安装app的权限管理
        for (PackageInfo pi : packs) {
            if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 //
                    && (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
                AppBeam item = new AppBeam();
                item.setAppName(pi.applicationInfo.loadLabel(pm).toString());//获取APP名
                item.setIcon(pi.applicationInfo.loadIcon(pm));//获取app图标
                item.setPackageInfo(pi.applicationInfo.packageName);//获取包的信息
                list.add(item);//列表添加app
            }


        }

        return list;
    }

}
